#include "networkresponse.h"
#include <QNetworkReply>
#include <QDebug>

using namespace Network;

/**
 * @brief Response::Response
 * @param parent
 */
Response::Response(QObject *parent) :
    QObject(parent),
    m_error(None),
    m_message("Successed!!!"),
    m_errorResponsed(0)
{
}

void Response::parse(QNetworkReply &reply)
{
    QNetworkReply::NetworkError error = reply.error();
    if (error != QNetworkReply::NoError) {
        m_error = Network;
        m_message = reply.errorString();
        return;
    }
    QByteArray data = reply.readAll();
//    qDebug() << "======================================================================";
//    qDebug() << data;
    parse(data);
}

/**
 * @brief Response::setError
 * @param error
 * @param message
 */
void Response::setError(const Error &error, const QString &message, const int errorResponsed)
{
    m_error = error;
    m_message = message;
    m_errorResponsed = errorResponsed;
}


